<template>
  <div>
    <TopFilter :list="topFilterList" :collapse="false" @filterChange="changeHandle" @onCollapse="collapseHandle"></TopFilter>
    <FilterTable
      height="400"
      :selectionType="selectionType"
      ref="table"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="getfetchParams"
      datakey="records"
      :onColumnsChange="columns => (this.columns = columns)"
      :onSyncTableData="tableChangeFun"
      :onRowSelectChange="selectChange"
    >
    </FilterTable>
    <div class="dialogBottmView">
      <el-button size="small" type="primary" class="btnStyle" @click="submitBtn">确定 </el-button>
      <el-button size="small" type="primary" class="btnStyle" @click="closeDialog">取消 </el-button>
    </div>
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import { getOrderPartList } from '@/api/partsmanage/purchaseManage/purchaseSubmit';
import { ddlxArr } from './constant';

export default {
  name: 'purchaseSubmitAddPeij',
  components: {},
  mixins: [dictionary],
  data() {
    this.BaseTable = null;
    return {
      topFilterList: this.createTopFilterList(),
      visible: false,
      fetchApi: getOrderPartList,
      fetchParams: {
        xhrAbort: true
      },
      columns: this.createTableColumns(),
      selectArr: []
    };
  },
  props: {
    selectionType: {},
    params: {
      type: Object,
      default() {
        return {};
      }
    }
  }, //'single':'multiple' 单选多选
  computed: {
    getfetchParams() {
      return Object.assign({}, this.params, this.fetchParams);
    }
  },
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
    this.topFilterList.find(i => i.fieldName == 'bjpjsx').initialValue = this.params.bjpjsx;
  },
  methods: {
    tableChangeFun(data) {
      const disabledData = data.filter(i => !i.bjcgzx);
      this.BaseTable.SET_DISABLE_SELECT(disabledData);
    },
    selectChange(val) {
      this.selectArr = val;
      console.log(val);
    },
    createTableColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '配件代码',
          dataIndex: 'bjxmbh',
          sorter: true
        },
        {
          title: '配件名称',
          dataIndex: 'bjzwmc',
          sorter: true
        },
        {
          title: '配件属性',
          dataIndex: 'bjpjsx',
          sorter: true,
          dictItems: this.createDictList(5000)
        },
        {
          title: '销售索标识',
          dataIndex: 'bjdgbz',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '最小订购量',
          dataIndex: 'bjcgzx',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '首用车型',
          dataIndex: 'bjsycx',
          sorter: true
        },
        {
          title: '常规订货单价',
          dataIndex: 'xs',
          sorter: true
        },
        {
          title: '终端建议零售VIP价格',
          dataIndex: 'ls',
          sorter: true
        },
        {
          title: '终端建议零售价格',
          dataIndex: 'bx',
          sorter: true
        }
      ];
    },
    createTopFilterList() {
      return [
        {
          type: 'INPUT',
          label: '配件代码',
          fieldName: 'bjxmbh',
          placeholder: '配件代码...'
        },
        {
          type: 'INPUT',
          label: '配件名称',
          fieldName: 'bjzwmc',
          placeholder: '配件名称...'
        },
        {
          type: 'SELECT',
          label: '油电属性',
          fieldName: 'bjpjsx',
          placeholder: '请选择',
          disabled: !!this.params.bjpjsx,
          itemList: this.createDictList(5000)
        }
      ];
    },

    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },

    changeHandle(val) {
      this.fetchParams = Object.assign({}, val);
    },

    closeHandler(val, type) {
      this.visible = val;
      if (type === 'refresh') {
        // 重新加载
        this.fetchParams = { ...this.fetchParams };
      }
    },
    closeDialog() {
      this.$emit('closeDialog');
    },
    submitBtn() {
      if (this.selectArr.length == 0) {
        this.$notify.warning({ title: '提示信息', message: '请您选择配件' });
        return;
      }
      this.$emit('selectArr', this.selectArr);
    }
  }
};
</script>

<style lang="less" scoped>
.dialogBottmView {
  text-align: center;
}
</style>
